package com.ymatou.iapi.livebuyer.testcase;

import com.google.gson.JsonArray;
import com.ymatou.iapi.livebuyer.parameter.QuerySubscribeBean;
import com.ymatou.iapi.livebuyer.service.QuerySubscribeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.ArrayList;
import java.util.List;
/**
*批量查询是否订阅直播
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QuerySubscribe{
	private static QuerySubscribeBean querysubscribeBean;
	private static QuerySubscribeCall querysubscribeCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量查询是否订阅直播");
	}

	@Before
	public void caseUp() {
		querysubscribeBean=new QuerySubscribeBean();
		querysubscribeCall=new QuerySubscribeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querysubscribeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QuerySubscribe_001() {
		Logger.start(true,"批量查询是否订阅直播成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			Integer liveid=createlive.getId();
			int userid=1;
			LiveRoomCallService.SubscribeLive(liveid, userid);
			List<Integer> liveIdList=new ArrayList<>();
			liveIdList.add(liveid);
			querysubscribeBean.setLiveIdList(liveIdList);
			querysubscribeBean.setUserId(userid);
			querysubscribeCall.setData(querysubscribeBean);
			querysubscribeCall.callService();			
			Logger.verifyEquals("200", querysubscribeCall.getString("code"), "判断code");
			JsonArray ja = querysubscribeCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(1, ja.size(), "判断size");
			Logger.verifyIsContains(liveid.toString(), ja.toString(), "验证包含直播");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QuerySubscribe_002() {
		Logger.start(true,"批量查询是否订阅直播未订阅查询成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			Integer liveid=createlive.getId();
			int userid=1;
//			LiveRoomCallService.SubscribeLive(liveid, userid);
			List<Integer> liveIdList=new ArrayList<>();
			liveIdList.add(liveid);
			querysubscribeBean.setLiveIdList(liveIdList);
			querysubscribeBean.setUserId(userid);
			querysubscribeCall.setData(querysubscribeBean);
			querysubscribeCall.callService();			
			Logger.verifyEquals("200", querysubscribeCall.getString("code"), "判断code");
			JsonArray ja = querysubscribeCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(0, ja.size(), "判断size");
//			Logger.verifyIsContains(liveid.toString(), ja.toString(), "验证包含直播");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QuerySubscribe_003() {
		Logger.start(true,"批量查询多个是否订阅直播成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			Integer liveid=createlive.getId();
			
			List<Userinfo> list2 =new JUserWapper().select1KSeller();
			Userinfo uinfo2 = list2.get(0);
			LiveRoom createlive2 = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo2));
			Integer liveid2=createlive2.getId();
			
			int userid=1;
			LiveRoomCallService.SubscribeLive(liveid, userid);
			LiveRoomCallService.SubscribeLive(liveid2, userid);
			
			List<Integer> liveIdList=new ArrayList<>();
			liveIdList.add(liveid);
			liveIdList.add(liveid2);
			querysubscribeBean.setLiveIdList(liveIdList);
			querysubscribeBean.setUserId(userid);
			querysubscribeCall.setData(querysubscribeBean);
			querysubscribeCall.callService();			
			Logger.verifyEquals("200", querysubscribeCall.getString("code"), "判断code");
			JsonArray ja = querysubscribeCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(2, ja.size(), "判断size");
			Logger.verifyIsContains(liveid.toString(), ja.toString(), "验证包含直播");
			Logger.verifyIsContains(liveid2.toString(), ja.toString(), "验证包含直播2");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QuerySubscribe_004() {
		Logger.start(true,"不输入userid失败");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			Integer liveid=createlive.getId();
			List<Integer> liveIdList=new ArrayList<>();
			liveIdList.add(liveid);
			querysubscribeBean.setLiveIdList(liveIdList);
//			querysubscribeBean.setUserId(userid);
			querysubscribeCall.setData(querysubscribeBean);
			querysubscribeCall.callService();			
			Logger.verifyEquals("100", querysubscribeCall.getString("code"), "判断code");
			Logger.verifyIsContains("无效的用户编号", querysubscribeCall.getString("message"), "验证message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_QuerySubscribe_005() {
		Logger.start(true,"不输入liveIdList失败");
		try {
			querysubscribeBean.setUserId(1);
			querysubscribeCall.setData(querysubscribeBean);
			querysubscribeCall.callService();			
			Logger.verifyEquals("100", querysubscribeCall.getString("code"), "判断code");
			Logger.verifyIsContains("不能为空", querysubscribeCall.getString("message"), "验证message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QuerySubscribe_006() {
		Logger.start(true,"批量查询取消订阅是否订阅直播成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			int liveid=createlive.getId();
			int userid=1;
			LiveRoomCallService.SubscribeLive(liveid, userid);
			LiveRoomCallService.UnSubscribeLive(liveid, userid);
			List<Integer> liveIdList=new ArrayList<>();
			liveIdList.add(liveid);
			querysubscribeBean.setLiveIdList(liveIdList);
			querysubscribeBean.setUserId(userid);
			querysubscribeCall.setData(querysubscribeBean);
			querysubscribeCall.callService();			
			JsonArray ja = querysubscribeCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(0, ja.size(), "判断size");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QuerySubscribe_007() {
		Logger.start(true,"批量查询多个是否订阅直播成功,混合场景");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			Integer liveid=createlive.getId();
			
			List<Userinfo> list2 =new JUserWapper().select1KSeller();
			Userinfo uinfo2 = list2.get(0);
			LiveRoom createlive2 = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo2));
			Integer liveid2=createlive2.getId();
			
			int userid=1;
			LiveRoomCallService.SubscribeLive(liveid, userid);
//			LiveRoomCallService.SubscribeLive(liveid2, userid);
			
			List<Integer> liveIdList=new ArrayList<>();
			liveIdList.add(liveid);
			liveIdList.add(liveid2);
			querysubscribeBean.setLiveIdList(liveIdList);
			querysubscribeBean.setUserId(userid);
			querysubscribeCall.setData(querysubscribeBean);
			querysubscribeCall.callService();			
			Logger.verifyEquals("200", querysubscribeCall.getString("code"), "判断code");
			JsonArray ja = querysubscribeCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(1, ja.size(), "判断size");
			Logger.verifyIsContains(liveid.toString(), ja.toString(), "验证包含直播");
//			Logger.verifyIsContains(liveid2.toString(), ja.toString(), "验证包含直播2");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QuerySubscribe_008() {
		Logger.start(true,"批量查询多个是否订阅直播成功,混合场景（WxApp，App）");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			Integer liveid=createlive.getId();

			List<Userinfo> list2 =new JUserWapper().select1KSeller();
			Userinfo uinfo2 = list2.get(0);
			LiveRoom createlive2 = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo2));
			Integer liveid2=createlive2.getId();

			int userid=1;
			LiveRoomCallService.SubscribeLive(liveid, userid);
			LiveRoomCallService.SubscribeLiveWx(liveid2, userid);

			List<Integer> liveIdList=new ArrayList<>();
			liveIdList.add(liveid);
			liveIdList.add(liveid2);
			querysubscribeBean.setLiveIdList(liveIdList);
			querysubscribeBean.setUserId(userid);
			querysubscribeCall.setData(querysubscribeBean);
			querysubscribeCall.callService();
			Logger.verifyEquals("200", querysubscribeCall.getString("code"), "判断code");
			JsonArray ja = querysubscribeCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(2, ja.size(), "判断size");
			Logger.verifyIsContains(liveid2.toString(), ja.toString(), "验证包含直播1");
			Logger.verifyIsContains(liveid2.toString(), ja.toString(), "验证包含直播2");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}